package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.TbOperateLog;
import com.ruoyi.system.service.ITbOperateLogService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: zhoupeng
 * @date: 2021/9/12 16:51
 * @descreption: 操作日志控制层
 */
@Controller
@RequestMapping("/operate")
public class TbOperateLogController extends BaseController {

    @Resource
    private ITbOperateLogService operateLogService;

    @RequiresPermissions("operate:view")
    @GetMapping()
    public String user() {
        return "system/log/tbOperate";
    }

    /**
     * 查询数据
     */
    @RequiresPermissions("operate:log:list")
    @PostMapping("list")
    @ResponseBody
    public TableDataInfo list(TbOperateLog tbOperateLog) {
        startPage();
        List<TbOperateLog> list = operateLogService.selectOperateLogList(tbOperateLog);
        return getDataTable(list);
    }

    /**
     * 查询详情
     */
    @RequiresPermissions("operate:log:detailList")
    @GetMapping("operateDetailList/{id}")
    public String detailList(@PathVariable("id") Long id, ModelMap mmap) {
        TbOperateLog tbOperateLog = new TbOperateLog();
        tbOperateLog.setId(id);
        tbOperateLog = operateLogService.selectOperateLogList(tbOperateLog).get(0);
        mmap.put("tbOperateLog", tbOperateLog);
        return "system/log/operateDetail";
    }

    @Log(title = "操作日志管理", businessType = BusinessType.EXPORT)
    @RequiresPermissions("operate:log:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TbOperateLog tbOperateLog) {
        List<TbOperateLog> list = operateLogService.selectOperateLogList(tbOperateLog);
        ExcelUtil<TbOperateLog> util = new ExcelUtil<>(TbOperateLog.class);
        return util.exportExcel(list, "操作日志数据");
    }

}
